package com.zy.composeworld.demo.demo1

import android.util.Log
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Notifications
import androidx.compose.material.icons.filled.Person
import androidx.compose.material3.BottomAppBar
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.zy.composeworld.R
import com.zy.composeworld.demo.demo1.screens.HomeScreen
import com.zy.composeworld.demo.demo1.screens.MineScreen
import com.zy.composeworld.demo.demo1.screens.StudyScreen
import com.zy.composeworld.model.entity.NavigationItem
import com.zy.composeworld.ui.screens.navigation.ReplyRoute
import com.zy.composeworld.ui.screens.navigation.TOP_LEVEL_DESTINATIONS


@Preview
@Composable
fun MainFrame() {
    val navigationItems = listOf(
        NavigationItem("主页", icon = Icons.Filled.Home),
        NavigationItem("学习", icon = Icons.Filled.Notifications),
        NavigationItem("我的", icon = Icons.Filled.Person),
    )

    var selectedDestination by remember { mutableStateOf("主页") }

    Scaffold(topBar = {

    }, bottomBar = {
        NavigationBar(modifier = Modifier.fillMaxWidth()) {
            navigationItems.forEach { replyDestination ->
                NavigationBarItem(
                    selected = selectedDestination == replyDestination.title,
                    onClick = {
                        Log.d("MainFrame", "click = $replyDestination")
                        selectedDestination = replyDestination.title
                    },
                    icon = {
                        Icon(
                            imageVector = replyDestination.icon,
                            contentDescription = null
                        )
                    },
                    label = {
                        Text(text = replyDestination.title)
                    },
                    alwaysShowLabel = false
                )
            }
        }
    }) { innerPadding ->
        Column(
            modifier = Modifier.padding(innerPadding),
            verticalArrangement = Arrangement.spacedBy(16.dp),
        ) {
            when (selectedDestination) {
                "主页" -> HomeScreen()
                "学习" -> StudyScreen()
                "我的" -> MineScreen()
            }
        }
    }
}


@Composable
fun EmptyComingSoon(
    modifier: Modifier = Modifier
) {
    Column(
        modifier = modifier.fillMaxSize(),
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        Text(
            modifier = Modifier.padding(8.dp),
            text = stringResource(id = R.string.empty_screen_title),
            style = MaterialTheme.typography.titleLarge,
            textAlign = TextAlign.Center,
            color = MaterialTheme.colorScheme.primary
        )
        Text(
            modifier = Modifier.padding(horizontal = 8.dp),
            text = stringResource(id = R.string.empty_screen_subtitle),
            style = MaterialTheme.typography.bodySmall,
            textAlign = TextAlign.Center,
            color = MaterialTheme.colorScheme.outline
        )
    }
}

@Composable
fun ComingSoonPreview() {
    EmptyComingSoon()
}